package info.akabana.yui.examples.fx3.empinfo.helper
{
	import info.akabana.yui.examples.fx3.empinfo.view.EmpInfoView;
	import info.akabana.yui.examples.fx3.model.EmpInfoModel;
	
	import mx.collections.ArrayCollection;
	
	import org.seasar.akabana.yui.framework.ns.viewpart;

	public class EmpInfoSetHelper
	{
		public var view:EmpInfoView;
		
		public function setPosition(position:ArrayCollection):void {
			view.cmbbxPosition.dataProvider = position;
		}
			
		public function setModel(model:EmpInfoModel):void {
			
			view.lblEmployNo.text = model.empNo;
			view.txtinptName.text = model.name;
			view.txtinptEmail.text = model.email;
			view.txtinptEmailMobile.text = model.emailMobile;
			view.txtinptMobilePhone.text = model.mobilePhone;
			view.cmbbxPosition.selectedItem = 
				getPostionCode(model.positionCode);
			
			view.data = model;
			
			view.btnUpdate.visible = true;
		}
		
		private function getPostionCode(code:String):Object {
			var position:ArrayCollection = 
				view.cmbbxPosition.dataProvider as ArrayCollection;
			
			for each(var pos:Object in position)  {
				if (pos.code == code) {
					return pos;
				}
			}
			return null;
		}
	}
}